package com.njym.java.security.admin.rest;

import com.njym.java.security.admin.biz.SupportBussinessBiz;
import com.njym.java.security.admin.entity.SupportBussiness;
import com.njym.java.security.common.rest.BaseController;
import com.njym.java.security.common.util.ResponseUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import tk.mybatis.mapper.entity.Example;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("supportBussiness")
public class SupportBussinessController extends BaseController<SupportBussinessBiz,SupportBussiness> {

    @RequestMapping(value = "/choose", method = RequestMethod.GET)
    @ResponseBody
    public Object choose(String name){
        Example example = new Example(SupportBussiness.class);
        example.createCriteria().andLike("name", "%" + name + "%").andEqualTo("attr1",1);
        List<SupportBussiness> list = baseBiz.selectByExample(example);
//        List<SupportBussinessVo> list = baseBiz.choose(name);
        List<Map<String, Object>> brandList = new ArrayList<>(list.size());
        Map<String, Object> data = new HashMap<>(1);
        for (SupportBussiness sb : list) {
            Map<String, Object> b = new HashMap<>(2);
            b.put("value", sb.getName());
            b.put("id", sb.getId());
            brandList.add(b);
        }
        data.put("bussinesses", brandList);
        return ResponseUtil.ok(data);
    }

}